﻿package mortal.game.view.mount.newMountModuel
{
    import Message.Client.*;
    import Message.DB.Tables.*;
    import Message.Public.*;
    import com.mui.controls.*;
    import com.mui.utils.*;
    import flash.utils.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.info.item.*;
    import mortal.game.resource.tableConfig.*;
    import mortal.game.utils.*;
    import mortal.game.view.mount.data.*;
    import mortal.game.view.skill.*;
    import mortal.game.view.skill.panel.render.*;
    import mortal.mvc.core.*;

    public class MountSkillPart extends GSprite
    {
        private var _dicSkillItem:Dictionary;

        public function MountSkillPart()
        {
            this._dicSkillItem = new Dictionary();
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this.createSkillList();
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            this._dicSkillItem = new Dictionary();
            super.disposeImpl(param1);
            return;
        }// end function

        private function createSkillList() : void
        {
            var _loc_1:SkillItem = null;
            var _loc_3:TMountConfig = null;
            var _loc_4:TSkill = null;
            var _loc_5:SkillInfo = null;
            var _loc_6:int = 0;
            var _loc_7:String = null;
            var _loc_2:* = MountConfig.instance.mountMap;
            for (_loc_7 in _loc_2)
            {
                
                _loc_3 = _loc_2[_loc_7];
                if (_loc_3.skillList)
                {
                    _loc_5 = new SkillInfo();
                    _loc_4 = SkillConfig.instance.getInfoById(int(_loc_3.skillList));
                    _loc_5.tSkill = _loc_4;
                    _loc_1 = UICompomentPool.getUICompoment(OtherSkillItem);
                    _loc_1.setBg(ImagesConst.EquipItemBg, 7, 7);
                    _loc_1.setSize(48, 48);
                    _loc_1.x = 56 * _loc_6 + 73;
                    _loc_1.y = 18;
                    _loc_1.doubleClickEnabled = true;
                    _loc_1.skillInfo = _loc_5;
                    this.pushUIToDisposeVec(_loc_1);
                    this._dicSkillItem[_loc_4.posType] = _loc_1;
                    this.addChild(_loc_1);
                    _loc_6++;
                }
            }
            return;
        }// end function

        public function updateSkillGrid(param1:MountData) : void
        {
            var _loc_4:TSkill = null;
            var _loc_5:OtherSkillItem = null;
            var _loc_6:TMountConfig = null;
            var _loc_2:* = param1.mountLevel;
            var _loc_3:* = MountConfig.instance.mountMap;
            for each (_loc_5 in this._dicSkillItem)
            {
                
                for each (_loc_6 in _loc_3)
                {
                    
                    if (_loc_6.skillList)
                    {
                        _loc_4 = SkillConfig.instance.getInfoById(int(_loc_6.skillList));
                        if (_loc_4.posType == _loc_5.skillInfo.tSkill.posType)
                        {
                            if (_loc_2 >= _loc_6.code)
                            {
                                _loc_5.isShowLock = false;
                            }
                            else
                            {
                                _loc_5.isShowLock = true;
                            }
                            break;
                        }
                    }
                }
            }
            this.updateSkill();
            return;
        }// end function

        public function updateSkill() : void
        {
            var _loc_3:SkillInfo = null;
            var _loc_4:SkillInfo = null;
            var _loc_7:OtherSkillItem = null;
            var _loc_1:* = SkillUtil.getLearnedSkillByType(ESkillCategory._EMountSkill);
            var _loc_2:* = new Dictionary();
            var _loc_5:int = 0;
            while (_loc_5 < _loc_1.length)
            {
                
                _loc_3 = _loc_1[_loc_5];
                _loc_4 = _loc_2[_loc_3.tSkill.posType] as SkillInfo;
                if (_loc_4 == null || _loc_4 && _loc_3.tSkill.skillLevel > _loc_4.tSkill.skillLevel)
                {
                    _loc_2[_loc_3.tSkill.posType] = _loc_3;
                }
                _loc_5++;
            }
            var _loc_6:int = 0;
            for each (_loc_7 in this._dicSkillItem)
            {
                
                _loc_3 = _loc_2[_loc_7.skillInfo.tSkill.posType];
                if (_loc_3)
                {
                    _loc_7.skillInfo = _loc_3;
                    _loc_7.hasLearnSkill = true;
                    continue;
                }
                _loc_7.hasLearnSkill = false;
            }
            this.updateSkillbook();
            return;
        }// end function

        public function updateSkillbook() : void
        {
            var _loc_2:TSkill = null;
            var _loc_3:OtherSkillItem = null;
            var _loc_4:ItemData = null;
            var _loc_1:* = Cache.instance.pack.backPackCache.getItemsByGroupCategoryAndType(EGroup._EGroupStuff, EStuff._EStuffAdvance, EAdvanceType._EAdvanceTypePlayer);
            for each (_loc_3 in this._dicSkillItem)
            {
                
                _loc_3.isShowUpgradeBtn = false;
                _loc_3.setState(OtherSkillItem.stateType_no);
                if (!_loc_3.isLocking)
                {
                    for each (_loc_4 in _loc_1)
                    {
                        
                        if (ItemsUtil.isOtherSkillBook(_loc_4))
                        {
                            _loc_2 = SkillConfig.instance.getInfoById(_loc_4.itemInfo.effect);
                            if (_loc_2 && _loc_3.skillInfo.tSkill.posType == _loc_2.posType)
                            {
                                if (_loc_3.hasLearnSkill)
                                {
                                    if (_loc_2.skillLevel - _loc_3.skillInfo.tSkill.skillLevel == 1)
                                    {
                                        _loc_3.isShowUpgradeBtn = true;
                                        _loc_3.setState(OtherSkillItem.stateType_canAdvance);
                                        _loc_3.upgradeParam = _loc_4;
                                        _loc_3.callBack = this.upgradeSkill;
                                        break;
                                    }
                                    else
                                    {
                                        _loc_3.isShowUpgradeBtn = false;
                                        _loc_3.setState(OtherSkillItem.stateType_no);
                                    }
                                }
                                else if (_loc_2.skillLevel == 1)
                                {
                                    _loc_3.isShowUpgradeBtn = true;
                                    _loc_3.setState(OtherSkillItem.stateType_canLearn);
                                    _loc_3.upgradeParam = _loc_4;
                                    _loc_3.callBack = this.upgradeSkill;
                                    break;
                                }
                                else
                                {
                                    _loc_3.isShowUpgradeBtn = false;
                                    _loc_3.setState(OtherSkillItem.stateType_no);
                                }
                                continue;
                            }
                            _loc_3.isShowUpgradeBtn = false;
                            _loc_3.setState(OtherSkillItem.stateType_no);
                        }
                    }
                }
            }
            return;
        }// end function

        private function upgradeSkill(param1:ItemData) : void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.MountUseSkillBook, param1));
            return;
        }// end function

    }
}
